package com._520it.crm.service.impl;

import com._520it.crm.domain.AccountInfo;
import com._520it.crm.mapper.AccountInfoMapper;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.QueryObject;
import com._520it.crm.service.IAccountInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * Created by 呆 on 2017/10/3.
 */
@Service
public class AccountInfoServiceImpl implements IAccountInfoService {
    @Autowired
    private AccountInfoMapper accountInfoMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
        return accountInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(AccountInfo accountInfo) {
        return accountInfoMapper.insert(accountInfo);
    }

    @Override
    public AccountInfo selectByPrimaryKey(Long id) {
        return accountInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<AccountInfo> selectAll() {
        return accountInfoMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(AccountInfo accountInfo) {
        return accountInfoMapper.updateByPrimaryKey(accountInfo);
    }

    @Override
    public PageResult query(QueryObject qo) {
        Integer totalCount = accountInfoMapper.queryforCount(qo);
        if (totalCount==0){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<AccountInfo> data = accountInfoMapper.queryforList(qo);
        return new PageResult(totalCount,data);
    }

    @Override
    public void saveAccountInfo(AccountInfo accountInfo, String applyClient) {
        //先保存账户信息 再维护中间表
        accountInfoMapper.insert(accountInfo);
        accountInfoMapper.insertRelation(accountInfo.getId(),applyClient);
    }


}
